/*
 *        PageSupport.java  Copyright (c) 2021. cc01cc. All rights reserved.
 *
 *        Licensed under the Apache License, Version 2.0 (the "License");
 *        you may not use this file except in compliance with the License.
 *        You may obtain a copy of the License at
 *
 *            http://www.apache.org/licenses/LICENSE-2.0
 *
 *        Unless required by applicable law or agreed to in writing, software
 *        distributed under the License is distributed on an "AS IS" BASIS,
 *        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *        See the License for the specific language governing permissions and
 *        limitations under the License.
 */

package util;

/**
 * @author cc01cc
 */
public class PageSupport {
    // 单位数据总量（例：商品总数目）
    private int unitNumTotal = 0;
    // 单位页面可容纳的数据条数
    private int pageNumLimit = 0;
    // 当前页码
    private int pageNumCurrent = 1;
    // 总页数
    private int pageNumTotal = 1;

    public int getUnitNumTotal(){ return unitNumTotal; }
    public void setUnitNumTotal(int unitNumTotal){
        if(unitNumTotal >= 0){
            this.unitNumTotal = unitNumTotal;
        }
    }

    public int getPageNumLimit(){ return pageNumLimit; }
    public void setPageNumLimit(int pageNumLimit){
        if(pageNumLimit > 0){
            this.pageNumLimit = pageNumLimit;
        }
    }

    public int getPageNumCurrent(){ return pageNumCurrent; }
    public void setPageNumCurrent(int pageNumCurrent){
        if(pageNumCurrent > 0){
            this.pageNumCurrent = pageNumCurrent;
        }
    }

    public int getPageNumTotal(){ return pageNumTotal; }
    // 页面即使没有记录，也应该留有一页
    public void setPageNumTotal(int pageNumTotal){
        if(pageNumTotal > 0){
            this.pageNumTotal = pageNumTotal;
        }
    }
    public void setPageNumTotal(){
        int pageNumTotal = 1;
        pageNumTotal = this.unitNumTotal%this.pageNumLimit;
        if(pageNumTotal == 0){ this.pageNumTotal = pageNumTotal; }
        else if(pageNumTotal > 0){ this.pageNumTotal = pageNumTotal + 1;}
        else {this.pageNumTotal = 1;}
    }
}
